function Complete-ArmTemplateParameterFile {
    [CmdletBinding()]
    param (
        [Parameter(Mandatory = $true)][Parameters]$Parameters
    )

    # For convenience.
    $File = $Parameters.LSInsight.ArmTemplateParameterFile

    # Get 'FullyQualifiedDomainName' if it is missing.
    if (!$Parameters.LSInsight.Server.FullyQualifiedDomainName) {
        $params = @{
            ResourceGroupName = $Parameters.Azure.ResourceGroup
            ServerName = $Parameters.LSInsight.Server.Name
        }
        $AzureSQLServer = Get-AzSqlServer @params
        $Parameters.LSInsight.Server.FullyQualifiedDomainName = $AzureSQLServer.FullyQualifiedDomainName
    }

    # Set LS Central parameters if it is SaaS.
    if ($Parameters.LSCentral.Placement -eq 'SaaS_In_Cloud') {
        $Parameters.LSCentral.Server.Credential = $Parameters.LSInsight.Server.Credential
        $Parameters.LSCentral.Server.Name = $Parameters.LSInsight.Server.FullyQualifiedDomainName
        $Parameters.LSCentral.Database.Name = $Parameters.LSInsight.Database.Name
    }

    # Set 'Linked service' type to appropriate value.
    $LSInsightLinkedServiceType = if ($Parameters.LSInsight.Placement -eq 'On_Premises') { 'SqlServer' } else { 'AzureSqlDatabase' }
    $LSCentralLinkedServiceType = if ($Parameters.LSCentral.Placement -eq 'SaaS_In_Cloud') { 'AzureSqlDatabase' } else { 'SqlServer' }

    # Setting the parameters in the parameter template file.
    (Get-Content $File) -replace "PLACEHOLDER-LS-ADF-NAME", $Parameters.LSInsight.ADFv2.Name | Set-Content $File -Encoding Unicode
    (Get-Content $File) -replace "PLACEHOLDER-PIPELINE-DATESTART", $Parameters.LSInsight.ADFv2.TriggerStart.ToString('yyyy-MM-dd') | Set-Content $File -Encoding Unicode
    (Get-Content $File) -replace "PLACEHOLDER-PIPELINE-HOURSTART", $Parameters.LSInsight.ADFv2.TriggerStart.ToString('HH') | Set-Content $File -Encoding Unicode
    (Get-Content $File) -replace "PLACEHOLDER-LSINSIGHT-SERVER-NAME", ($Parameters.LSInsight.Server.FullyQualifiedDomainName -replace '\\+', '\\') | Set-Content $File -Encoding Unicode
    (Get-Content $File) -replace "PLACEHOLDER-LSINSIGHT-DATABASE-NAME", $Parameters.LSInsight.Database.Name | Set-Content $File -Encoding Unicode
    (Get-Content $File) -replace "PLACEHOLDER-LSINSIGHT-USERNAME", $Parameters.LSInsight.Server.Credential.UserName | Set-Content $File -Encoding Unicode
    (Get-Content $File) -replace "PLACEHOLDER-SOURCE-SERVER-NAME", ($Parameters.LSCentral.Server.Name -replace '\\+', '\\') | Set-Content $File -Encoding Unicode
    (Get-Content $File) -replace "PLACEHOLDER-SOURCE-DATABASE-NAME", $Parameters.LSCentral.Database.Name | Set-Content $File -Encoding Unicode
    (Get-Content $File) -replace "PLACEHOLDER-SOURCE-USERNAME", $Parameters.LSCentral.Server.Credential.UserName | Set-Content $File -Encoding Unicode
    (Get-Content $File) -replace "PLACEHOLDER-LSINSIGHT-LINKEDSERVICE-TYPE", $LSInsightLinkedServiceType | Set-Content $File -Encoding Unicode
    (Get-Content $File) -replace "PLACEHOLDER-LSCENTRAL-LINKEDSERVICE-TYPE", $LSCentralLinkedServiceType | Set-Content $File -Encoding Unicode
}